	var _todayday = "";
	var today_month = "";
	$("#clock").click(function(){
		$.toast("操作成功");
	})
	
	var _thisyear = "";
	var _thismonth = "";
	var _thisdate = "";
	var nowday = "";
	
	//入职时间的年月日
	var join_year = join_date.substring(0,4).replace(/\b(0+)/gi,"");
	var join_month = join_date.substring(5,7).replace(/\b(0+)/gi,"");
	var join_day = join_date.substring(8,10).replace(/\b(0+)/gi,"");
	
	//ajax日历
	$.ajax({
		type:"post",
		url:"./index.php?m=index&a=calendar",
		data:{pre:'60',next:'60'},
		async:false,
		success:function(ret){
			nowday = ret.today.year+"-"+ret.today.month+"-"+ret.today.day;
			_todayyear = ret.today.year;
			_todayweek = ret.today.week;
			_todaymonth = ret.today.month;
			_todayday = ret.today.day;
			if(_todayweek == "0"){
				_todayweek = "日";
			}else if(_todayweek == "1"){
				_todayweek = "一"
			}else if(_todayweek == "2"){
				_todayweek = "二"
			}else if(_todayweek == "3"){
				_todayweek = "三"
			}else if(_todayweek == "4"){
				_todayweek = "四"
			}else if(_todayweek == "5"){
				_todayweek = "五"
			}else if(_todayweek == "6"){
				_todayweek = "六"
			}
			
			//顶部的当前时间
			$(".title_data").html(_todayyear+"年"+(_todaymonth)+"月"+_todayday+"日")
			$(".title_week").html("周"+_todayweek)
			
			var arr=[];
			var arrmonth=[];
			var year = "";
			for(var i in ret.calendar){
				year = ret.calendar[i];
				for(var j in year){
					arr.push(year[j])
				}
			}	
			
			//给每个轮播页面插入当前月份
			for(var year in ret.calendar){
				for(var mon in ret.calendar[year]){
					html = "<div class='swiper-slide' month='"+mon+"'><div class='month'><div class='row'></div><div class='row'></div><div class='row'></div><div class='row'></div><div class='row'></div><div class='row'></div></div></div>";
					$(".swiper-wrapper").append(html);
				}
			}
			
			var nummonth = arr.length; //一个有多少个月
			//循环轮播页数
			for(var i=0;i<arr.length;i++){
				var html = '';
				var _thishtml = '';
				var weekhtml = '';
				var prevarr = arr;
				var nextarr = arr;
				var _monthlength = arr[i].length;
				var firstweek = arr[i][0].week; //第一天是周几
				var lastweek = arr[i][arr[i].length-1].week; //最后一天是周几
				var nextweek = 6-lastweek;  //上个月最后一周有多少天
				if(lastweek == "0"){
					lastweek = 6;
				}
				
				//插入上个月最后一个星期的数据
				for(var k=0;k<firstweek;k++){
					prevarr[i].unshift(" ");
				}
				
				var nextlength ="";
				
				
				//循环每个月的星期row
				for(var h=0;h<arr[i].length;h++){
					//循环一星期的每一天day
					for(var j =0;j<7;j++){
						var num = 7*h+j;
						if(num <　arr[i].length){
							var active = "";
							var absenteeism = "";
							var absenteeism_red="absenteeism_red";
							var isclick = "";
							var normal = "";
							var type = 0;
							var attendance = arr[i][num].attendance;
							var festival = arr[i][num].festival;
							var apply_wait = arr[i][num].apply_wait;
							var apply_text = "";
							var out_text = "";
							var kuanggong_text = "";
							var leave_text = "";
							var overtime_text = "";
							var festival_text = "";
							var patch_text = "";
							var b_color = "";	
							//是否工作日
							var iswork = function(day){
								if(day.week == "0" || day.week == "6"){
									if(day.festival.type == "2"){
										return true;
									}else{
										return false;
									}
								}else{
									if(day.festival.type == "1"){
										return false;
									}else{
										return true;
									}
								}
							}
							
							
							//提交了申请,未通过
							if(apply_wait == "1"){
								apply_text = "申";
							}
							
							//当天以后的日期不显示状态
							if(arr[i][num].month > _todaymonth){
								absenteeism_red = "";
								
							}
							if(arr[i][num].day > _todayday && arr[i][num].month == _todaymonth){
								absenteeism_red = "";
							}
							
							//假期
							if(festival !== undefined){
								var festival_title = festival.title; //假期名字
								if(festival.type == "1"){
									type = festival.type;
									festival_text = "假";  
									b_color = "#9dfe8a";
								}else if(festival.type == "2"){
									type = festival.type;
									festival_text = "班";
								}
							}
							if(attendance !== undefined){
								if(attendance.overtime > 0 ){
									overtime_text = "加";
								}
								//缺勤
								if(attendance.stu_absent>0){
									absenteeism = "absenteeism";
								}
								//显示当前天
								if(arr[i][num].day == _todayday && arr[i][num].month == _todaymonth){
									active = "active";
									absenteeism_red="";
								}
								//通过了请假申请,改变了考勤时间
								if(attendance.leave_compensatory > 0 || attendance.leave_annual > 0 || attendance.leave_casual > 0 ||  attendance.leave_other > 0 || attendance.leave_sick > 0 || attendance.leave_marriage > 0 || attendance.leave_maternity > 0 || attendance.leave_paternity > 0 || attendance.leave_sick_min > 0 || attendance.leave_sick_full > 0 || attendance.leave_sick_half > 0){
									leave_text = "假";
								}
								//通过了外出申请
								if(attendance.leave_evection > 0 || attendance.leave_long_distance > 0){
									out_text = "外";
								}
								//通过了补打卡申请
								if(arr[i][num].apply_4_succ == "1"){
									patch_text = "补";
								}
								//迟到+早退>= 180分钟 的，显示旷工
								if (attendance.stu_kuanggong == true) {
									kuanggong_text = "旷";
								}
								var workday = iswork(arr[i][num]);
								
								var hei = 0;
								var day_absenteeism = "";
								if(attendance.length !== 0){
									isclick = "yes";
									absenteeism_red = "";
									if(arr[i][num].day < _todayday && arr[i][num].month == _todaymonth){
										normal = "normal";
									}else if(arr[i][num].month < _todaymonth){
										normal = "normal";
									}
									var duty_on_h = "";
									if(attendance.duty_on != 0 || attendance.stu_absent>0){
										day_absenteeism = "day_absenteeism";
										hei = Math.round(attendance.stu_absent / 480 * 10000) / 100.00;
										
										if (hei > 100 ) {
											hei = 100;
										}else if(hei<10 && hei>0){
											hei = 10;
										}else if(hei<=0){
											hei = 0;
										}
										//当天不显示缺勤
										if(arr[i][num].day == _todayday && arr[i][num].month == _todaymonth){
											b_color='white';
											hei=100;
											day_absenteeism = "";
											active = "active";
											absenteeism_red=" ";
										}
									}
								}
								var display = "";
								var opacity = "";
								var duty_off_h = attendance.duty_off;
								if(duty_off_h){
									duty_off_h = duty_off_h.substring(0,2);
									duty_off_h = Number(duty_off_h)
								}
								if(workday == true){
									//9~18时上班
									if(attendance.zan == "1" && duty_off_h < 20 && duty_off_h >= 18){
										display = "inline-block";
									}
									//入职时间
									if(join_year > arr[i][num].year || join_year == arr[i][num].year){
										if(arr[i][num].month< Number(join_month)){
											absenteeism_red = "";
										}else if(arr[i][num].month == join_month && arr[i][num].day <= Number(join_day)){
											absenteeism_red = "";
										}else if(arr[i][num].month > _todaymonth){
												absenteeism_red = "";
										}else if(arr[i][num].month == _todaymonth && arr[i][num].day >= _todayday){
												absenteeism_red = "";
										}
									}
								}else if(workday == false){
									absenteeism_red = "";
								}
								_thishtml = "<div class='day "+normal+" "+absenteeism_red+" "+absenteeism+"'><div class='"+day_absenteeism+" ' style='height:"+hei+"%;background-color:"+b_color+"'><span class='data "+active+" '"+ 
								"click = '"+isclick+"'"+
								"duty_on='"+attendance.duty_on+"'"+
								"duty_off='"+attendance.duty_off+"'"+
								"work_actual='"+attendance.work_actual+"'"+
								"work_effect='"+attendance.work_effect+"'"+
								"overtime='"+attendance.overtime+"'"+
								"stu_absent='"+attendance.stu_absent+"'"+
								"leave_compensatory='"+attendance.leave_compensatory+"'"+
								"leave_casual='"+attendance.leave_casual+"'"+
								"leave_evection='"+attendance.leave_evection+"'"+
								"leave_sick='"+attendance.leave_sick+"'"+
								"leave_other='"+attendance.leave_other+"'"+
								"leave_annual='"+attendance.leave_annual+"'"+
								"leave_marriage='"+attendance.leave_marriage+"'"+
								"leave_maternity='"+attendance.leave_maternity+"'"+
								"leave_paternity='"+attendance.leave_paternity+"'"+
								"leave_sick_full='"+attendance.leave_sick_full+"'"+
								"leave_sick_half='"+attendance.leave_sick_half+"'"+
								"leave_sick_min='"+attendance.leave_sick_min+"'"+
								
								"leave_antenatal='"+attendance.leave_antenatal+"'"+
								"leave_awaiting_delivery='"+attendance.leave_awaiting_delivery+"'"+
								"leave_funeral='"+attendance.leave_funeral+"'"+
								"leave_breastfeeding='"+attendance.leave_breastfeeding+"'"+
								
								
								
								
								"week='"+arr[i][num].week+"'"+
								"year='"+arr[i][num].year+"'"+
								"festival_title='"+festival_title+"'"+
								"festival='"+type+"'"+
								"month='"+arr[i][num].month+"'>"+arr[i][num].day+"</span>"+
								"<span class='like' style='display:"+display+"'></span>"+
								"<span class='apply'>"+apply_text+"</span>"+
								"<span class='out'>"+out_text+"</span>"+
								"<span class='patch'>"+patch_text+"</span>"+
								"<span class='festival compensatory'>"+kuanggong_text+"</span>"+
								"<span class='leave'>"+leave_text+"</span>"+
								"<span class='overtime'>"+overtime_text+"</span>"+
								"<span class='festival'>"+festival_text+"</span></div></div>";
							}else{
								_thishtml = "<div class='day'></div>";
							}
							$(".swiper-wrapper .swiper-slide:eq("+i+") .month .row:eq("+h+")").append(_thishtml);
						}
					}
				}
			}
		}
	});
	
	
	var initialSlide = "";
	$(".swiper-slide").each(function(){
		var month = $(this).attr("month");
		if(month == _todaymonth){
			initialSlide = $(".swiper-slide").index(this);
		}
	})
	
	
	var active_min = $("#active_month .que_min span").html();
	var last_min = $("#last_month .que_min span").html();
	//轮播
  	var mySwiper = new Swiper ('.swiper_calendar', {
  		initialSlide :initialSlide,
	  	paginationClickable: true,
		direction: 'horizontal',
		loop: false,
		onSlideChangeStart: function(swiper){
			var month = $(".swiper-slide:eq("+swiper.activeIndex+")").attr("month");
			$(".title_month").html(month+"月")
			$(".last_month").html(month)
			if(month == (Number(_todaymonth)-1)){
				if(last_min == "0"){
					$("#last_month").hide();
				}else{
					$("#last_month").show();
				}
			}else{
				$("#last_month").hide();
			}
			if(month == _todaymonth){
				if(active_min == "0"){
					$("#active_month").hide();
				}else{
					$("#active_month").show();
				}
			}else{
				$("#active_month").hide();
			}
	  }
	})  
	//点击回到当天的轮播
	$(".title_ul").click(function(){
		mySwiper.slideTo(initialSlide, 1000, false);
		$(".title_month").html(_todaymonth+"月");
	})
	
	
	//点击日期显示详情
	$("body").on("click",".day .data",function(){
		var html = "";
		var click = $(this).attr("click");
		var y = $(this).attr("year");
		var m = $(this).attr("month");
		var d = $(this).html();
		var apply = "";
		duty_on = $(this).attr("duty_on");
		show_on = duty_on;
		duty_on = duty_on.substring(0,5);
		duty_off = $(this).attr("duty_off");
		show_off = duty_off;
		duty_off = duty_off.substring(0,5);
		work_actual = $(this).attr("work_actual");
		work_effect = $(this).attr("work_effect");
		overtime = $(this).attr("overtime");
		stu_absent = $(this).attr("stu_absent");
		leave_compensatory = $(this).attr("leave_compensatory"); //补休
		leave_casual = $(this).attr("leave_casual"); //事假
		leave_evection = $(this).attr("leave_evection"); //外出
		leave_sick = $(this).attr("leave_sick"); //病假
		leave_other = $(this).attr("leave_other"); //其他
		leave_marriage = $(this).attr("leave_marriage"); //婚假
		leave_maternity = $(this).attr("leave_maternity"); //产假
		leave_paternity = $(this).attr("leave_paternity"); //陪产假
		leave_annual = $(this).attr("leave_annual"); // 年假
		leave_sick_min = $(this).attr("leave_sick_min"); //病假工资
		leave_sick_half = $(this).attr("leave_sick_half"); //病假半日薪
		leave_sick_full = $(this).attr("leave_sick_full"); //病假全日薪
		leave_antenatal = $(this).attr('leave_antenatal')//产检
		leave_awaiting_delivery = $(this).attr('leave_awaiting_delivery')//待产
		leave_funeral = $(this).attr('leave_funeral')//丧假
		leave_breastfeeding = $(this).attr('leave_breastfeeding')//哺乳
		festival_title = $(this).attr("festival_title"); // 假期名字
		
		
		if(stu_absent < 0){
			stu_absent = "0.0";
		}
		var  isundefined = function(time){
			if(time == "NaN" || time == "undefined"){
				return 0;
			}else{
				return time;
			}
		}
			
		duty_on = isundefined(duty_on);
		show_on = isundefined(show_on);
		duty_off = isundefined(duty_off);
		show_off = isundefined(show_off);
		overtime = isundefined(overtime);
		stu_absent = isundefined(stu_absent);
		work_effect = isundefined(work_effect);
		work_actual = isundefined(work_actual);
		
		
		var on_h = "";
		var off_h = "";
		var on_m = "";
		var off_m = "";
		var on_time = "";
		var off_time = "";
		if(duty_on && duty_off){
			on_h = duty_on.substring(0,2);
			off_h = duty_off.substring(0,2);
			on_m = duty_on.substring(3,5);
			off_m = duty_off.substring(3,5);
			on_time = Number(on_h *60) + Number(on_m);
			off_time = Number(off_h *60) + Number(off_m);
		}
		
		//时间对比
		//补零
		var buling = function(a){
			if(a<10){
				return "0" + a;
			}else{
				return a;
			}
		}
		m = buling(m)
		d = buling(d)
		
		var start_time = "";
		var end_time = "";
		var w_start_time = "";
		//外出
		if((on_time - 9*60)>(18*60 - off_time)){
			w_start_time = "09:00";
			w_end_time = duty_on;
			b_duty = "09:00"
		}else{
			if(duty_off == "undef"){
				w_start_time = "09:00";
				w_end_time = "18:00";
				b_duty = "18:00";
			}else{
				w_start_time = duty_off;
				w_end_time = "18:00";
				b_duty = "18:00";
			}
		}
		//假期
		var j_start_time = "";
		var j_end_time = "";
		if((on_time - 9*60)>(18*60 - off_time)){
			j_start_time = "09:00";
			j_end_time = duty_on;
		}else{
			if(duty_off == "undef"){
				j_start_time = "09:00";
				j_end_time = "18:00";
			}else{
				j_start_time = duty_off;
				j_end_time = "18:00";
			}
		}
			
		//加班
		b_start_time = "20:00";
		b_end_time = "05:59";
		leave = [leave_compensatory,leave_casual,leave_evection,leave_sick,leave_other,leave_marriage,leave_maternity,leave_paternity,leave_annual,leave_sick_min,leave_sick_half,leave_sick_full,leave_antenatal,leave_awaiting_delivery,leave_funeral,leave_breastfeeding];
		leave_text = ["补休","事假","外出","病假","其他","婚假","产假","陪产假","年假","病假工资","病假(半日薪)","病假(全日薪)",'产检假','待产假','丧假','哺乳假'];
		for(var i in leave){
			var time_h = parseInt(leave[i]/60);
			var time_min = leave[i]%60;
			if(leave[i]>0){
				apply+= "<p>"+leave_text[i]+"申请: "+time_h+" 小时 "+time_min+" 分钟</p></br>"
			}
		}
		
		if(festival_title !== "undefined"){
			festival_html = "<p style='color:#f43;'>"+festival_title+"</p></br>";
		}else{
			festival_html = "";
		}
		
		//时分
		var overtime_h = parseInt(overtime/60);
		var overtime_min = overtime%60;
		var stu_absent_h = parseInt(stu_absent/60);
		var stu_absent_min = stu_absent%60;
		var work_effect_h = parseInt(work_effect/60);
		var work_effect_min = work_effect%60;
		var work_actual_h = parseInt(work_actual/60);
		var work_actual_min = work_actual%60;
		
		//添加次日
		if(on_h > off_h){
			show_off = show_off+"(次)";
		}
		//点击日期显示的信息
		html+="<p>上班打卡："+show_on+"</p></br>"+
			"<p>下班打卡："+show_off+"</p></br>"+
			"<p>加班时间："+overtime_h+" 小时 "+overtime_min+" 分钟</p></br>"+
			"<p>缺时时间："+stu_absent_h+" 小时 "+stu_absent_min+" 分钟</p></br>"+
			"<p>有效时间："+work_effect_h+" 小时 "+work_effect_min+" 分钟</p></br>"+
			"<p>实际时间："+work_actual_h+" 小时 "+work_actual_min+" 分钟</p></br>"+
	//		""+apply+""+
			""+festival_html+"";
		
		
		var outhref = "";
		var holidayhref = "";
		var overhref = "";
		var repairhref = "";
		var thisday = y+"-"+m+"-"+d;
		function toDate(str){
		    var sd=str.split("-");
		    return new Date(sd[0],sd[1],sd[2]);
		}
		
		outhref = "./index.php?g=&m=Apply&a=submit&type=1&year="+y+"&month="+m+"&day="+d+"&duty_on="+w_start_time+"&duty_off="+w_end_time+"";
		holidayhref = "./index.php?g=&m=Apply&a=submit&type=2&year="+y+"&month="+m+"&day="+d+"&duty_on="+j_start_time+"&duty_off="+j_end_time+"";
		overhref ="./index.php?g=&m=Apply&a=submit&type=3&year="+y+"&month="+m+"&day="+d+"&duty_on="+b_start_time+"&duty_off="+b_end_time+"";
		repairhref = "./index.php?g=&m=Apply&a=repair_submit&year="+y+"&month="+m+"&day="+d+"&duty="+b_duty+"";
		
		$.modal({
          	title: "",
          	text: html,
          	buttons: [
	            { text: "外出", onClick: function(){
	            	window.location.href = outhref;
	            }},
	            { text: "请假", onClick: function(){
	            	window.location.href = holidayhref;
	            }},
	            { text: "加班", onClick: function(){
	            	window.location.href = overhref;
	            }},
	            { text: "补打卡", onClick: function(){
	            	window.location.href = repairhref;
	            }},
	            { text: "取消", className: "default"},
	        ]
        });
	})
	
	